# -*- coding: utf-8 -*-

from utils.chars import *

def get_phonemes(word):
    return ' '.join( map (find_phoneme, word))

def find_phoneme_ch(char):
    try:  
        return phonemes_ch[ greek_ch.index(char)]
    except :
        print '%s not found' % (char)

def find_phoneme_dp(chars):
    return phonemes_dipthongs[ greek_dipthongs.index(chars)]

def find_phoneme(string):
          
        if string in greek_dipthongs:
            find_phoneme_dp(string)
        else:
            find_phoneme_ch(string)


import types
def get_phonemes2(word):
    assert (type(word)==types.UnicodeType)
    skip = False
    phons = []
    buf_chars = [u'',u'',]
    word = word + u''
    for c in word:
        buf_chars = buf_chars[1:]+[c]
        print u''.join(buf_chars).encode('utf-8')
        print buf_chars
        if(u''.join(buf_chars) in greek_dipthongs):
            phons.append(find_phoneme_dp(u''.join(buf_chars)))
            skip = True  
        else:
            if u''.join(buf_chars[:1]):
                if(not skip):
                    phons.append(find_phoneme_ch(u''.join(buf_chars[:1])))
                skip = False
    if(not skip):
        phons.append(find_phoneme_ch(u''.join(buf_chars[1:])))
    return u''.join(phons)
    
            
                             

        
        
if __name__=='__main__':

    #print 'test'
    #print find_phoneme('α')
    #print map (find_phoneme, 'τακης')
#    s= u'ορέστης'
#    print type(s)
#    print s.encode('utf-8')
    print get_phonemes2(u'μεϊμαράκος')
#    s = u'οιμια'
#    print type(s)
##    print s
#    buf = [s[0], s[1], s[2], s[3]]
#    print len(buf)
#    print len(s)
#    print u''.join(buf).encode('utf-8')
##    print (''.join(buf) in greek_dipthongs)
#    for c in s:
#        print (c in greek_ch)
#    print greek_ch[1].encode('utf-8')
#    print len(greek_ch[1])
        


    

    

